var datainfo = "";
var cardid="";
var type="";
var withdrawDeposit = {
    init: function () {
        this.getData();
        this.getCsInfos();
    },
    eventLisenter: function () {
        var off = true;
        var choose = false;
        $(".popIcon").click(function () {
            if (off) {
                off = false;
                $(".popIcon").attr("src", "../../img/withdrawDeposit/14.png");
                $(".chooseMold").css("display", "block");

            } else {
                $(".popIcon").attr("src", "../../img/withdrawDeposit/8.png");
                $(".chooseMold").css("display", "none");
                off = true;
            }
        });
        $(".Mold1").click(function () {
            type=2;
            $(".bankMsg").css("display", "block");
            $(".bankIcon").css("display","inline-block");
            $(".popIcon").attr("src", "../../img/withdrawDeposit/8.png");
            $(".bank").text(cardid);
            $(".chooseMold").css("display", "none");
            off = true;
            choose = true;
            if (choose && $(".mgetCsInfooney").val() > 0) {
                $(".sub1").css("background", "#cba86a");
            }else{
                $(".sub1").css("background", "#d3d3d3");
            }
        });
        $(".all").click(function () {
            var usableMoney = $(".usableMoney").text();
            $(".money").val(usableMoney);
            if (choose && $(".money").val() > 0) {
                $(".sub1").css("background", "#cba86a");
            }else{
                $(".sub1").css("background", "#d3d3d3");
            }
        });
        $(".money").on("input",function () {
            if($(".money").val()>0&&choose){
                $(".sub1").css("background", "#cba86a");
            }else{
                $(".sub1").css("background", "#d3d3d3");
            }
        });
        $(".sub1").click(function(){
            withdrawDeposit.draw($(".money").val());
        });
    },
    draw:function(money){
        new AjaxRequest({
            type: "post",
            url: apiService.doWithdraw,
            param: JSON.stringify({applyAmt:money,type:type}),
            callBack: function (res) {
                alert(res.message);
                $(".money").val("0.00");
                $(".sub1").css("background", "#d3d3d3");
                withdrawDeposit.getData();
            },
            failBack: function () {
            }
        });
    },
    getCsInfos:function(){
        new AjaxRequest({
            type: "get",
            url: apiService.getCsInfo,
            param: "",
            callBack: function (res) {
                $(".telp").attr("href","tel:"+res.payload.tel);
                var dom = `<img src="${res.payload.wechatImg}"/>`;
                $(".modal-dialog").append(dom);
            },
            failBack: function () {
            }
        });
    },
    getData: function () {
        new AjaxRequest({
            type: "get",
            url: apiService.withdrawInit,
            param: "",
            callBack: function (res) {
                if(res.success){
                    datainfo = res.payload.withdrawTypes;
                    $(".usableMoney").text(res.payload.availableAmt);
                    $(".noticeList").html(res.payload.ruleTip);
                    for(var i=0;i<res.payload.withdrawTypes.length;i++){
                        if(res.payload.withdrawTypes[i].type==1){
                            if(res.payload.withdrawTypes[i].status==0||res.payload.withdrawTypes[i].status==3){
                                $(".Mold2").click(function () {
                                    // $("#erWeiMa").css("display", "block");
                                    alert(datainfo[1].name);
                                    window.location.href="sendQrcode.html?user="+datainfo[1].name;
                                });
                            }else{
                                var weixinName=res.payload.withdrawTypes[i].name;
                                $(".bank2").text(res.payload.withdrawTypes[i].name);
                                $(".bankIcon2").css("display","none");
                                $(".Mold2").click(function () {
                                    type=1;
                                    $(".bankMsg").css("display", "block");
                                    $(".chooseMold").css("display", "none");
                                    $(".popIcon").attr("src", "../../img/withdrawDeposit/8.png");
                                    $(".bankIcon").css("display","none");
                                    $(".bank").text(weixinName);
                                    $(".redlining").text("微信提现");
                                    off = true;
                                    choose = true;
                                    if (choose && $(".money").val() > 0) {
                                        $(".sub1").css("background", "#cba86a");
                                    }else{
                                        $(".sub1").css("background", "#d3d3d3");
                                    }
                                });
                            }

                        }else if(res.payload.withdrawTypes[i].type==2){
                            cardid=res.payload.withdrawTypes[i].name;
                            $(".bank1").text(res.payload.withdrawTypes[i].name);
                        }
                    }
                }else{
                    alert(res.message);
                    if(res.code==302){
                        window.location.href= res.url;
                        return
                    }
                }

            },
            failBack: function () {
            }
        });
    }
}